onError

open fun onError(mp: MediaPlayer, what: Int, extra: Int): Boolean

Called when an error occurs during media playback. Logs the error and attempts to restart the player by posting the runnable (which calls initPlayer) with a delay. This retry mechanism is limited to a maximum of 20 attempts to prevent infinite loops.

Return

true if the error has been handled, false otherwise. Returning false (or true) often depends on whether the application wants the OnCompletionListener to be called subsequently. Check ExoPlayer's behavior. For robust error handling with ExoPlayer, using its specific Player.Listener is recommended over MediaPlayer listeners.

Parameters

mp

The MediaPlayer that encountered the error.

what

The type of error that has occurred.

extra

An extra code, specific to the error.